/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




function loadXMLDoc() //fungsi untuk load xmlhttp object
{
    var xmlHttp=null;
    try{
        xmlHttp = new XMLHttpRequest();
    }
    catch(e){
        //IE
        try{
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e){
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function viewMessageList(page){
    //buat get message sesuai page tertentu
    //dapetnya dari message_replies.php

    //get object
    var xh = loadXMLDoc();
    var url = "message_list.php?page="+page;

    xh.onreadystatechange = view;

    function view(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("message_content_0").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function getMessages(val, gid, msgid, page){
    //buat get message sesuai page tertentu
    //dapetnya dari message_replies.php

    //get object
    var xh = loadXMLDoc();
    var url = "message_replies.php?val="+val+"&gid="+gid+"&msgid="+msgid+"&page="+page;

    xh.onreadystatechange = view;

    function view(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("replies").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

var hide = 1;

function showNotif(usr_id){
    //ajax disini
    
    
    if (hide == 1){
        var xh = loadXMLDoc();
        var url = "notif_content.php?usrid="+usr_id;
        xh.onreadystatechange = view3;

        function view3(){
                document.getElementById("notif2").innerHTML = xh.responseText;
        }
        hide = 0;
        xh.open("GET",url,true);
        xh.send(null);

       
    }
    else{
        hideNotif(usr_id);
    }
    
}

function refresh_notif(){
     var xh = loadXMLDoc();
    var url = "notif_num.php";

    xh.onreadystatechange = view;

    function view(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("notif_number").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function hideNotif(usr_id){
    if (hide == 0){
        document.getElementById("notif2").innerHTML = "";
        hide = 1;
    }
    else{
        showNotif(usr_id);
    }
}

var hide2 = 1;

function showPopupProfile(){
    //ajax disini


    if (hide2 == 1){
        var xh = loadXMLDoc();
        var url = "profile_popup.php";
        xh.onreadystatechange = view3;

        function view3(){
                document.getElementById("profile_popup").innerHTML = xh.responseText;
        }
        hide2 = 0;
        xh.open("GET",url,true);
        xh.send(null);


    }
    else{
       hidePopupProfile()
    }

}

function hidePopupProfile(){
    if (hide2 == 0){
        document.getElementById("profile_popup").innerHTML = "";
        hide2 = 1;
    }
    else{
        showPopupProfile();
    }
}

var setvar;

var walltiga_interval;


function viewWallTiga(){
     var xh = loadXMLDoc();
        var url = "wall_tiga.php";

        xh.onreadystatechange = view_w;

        function view_w(){
            if (xh.readyState==4 && xh.status==200){
                document.getElementById("wallnya").innerHTML=xh.responseText;
            }
        }
        //URLnya

        xh.open("GET",url,true);
        xh.send(null);
}



function viewHome(){
    var xh = loadXMLDoc();
    var url = "home.php";

    xh.onreadystatechange = view_p;

    function view_p(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
        document.getElementById("notif_number").innerHTML = refresh_notif();
        clearInterval(setvar);
        setvar = setInterval('refresh_notif()',5000);
        viewWallTiga();
        clearInterval(walltiga_interval);
        walltiga_interval = setInterval('viewWallTiga()',60000);

        

    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    
    //URLnya
    //onreadystatechange
    //setInterval('viewHome()',3000);
    xh.open("GET",url,true);
    xh.send(null);
}
//
//window.onload=function(){
//    setInterval('viewHome()',3000);
//}

function viewProfile(){
    var xh = loadXMLDoc();
    var url = "profile.php";

    xh.onreadystatechange = view_p;

    function view_p(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewMessage(){
     var xh = loadXMLDoc();
    var url = "message.php";

    xh.onreadystatechange = view_p;

    function view_p(){
           if (xh.readyState==4 && xh.status==200){
                document.getElementById("content").innerHTML=xh.responseText;
                document.getElementById("notif_number").innerHTML = refresh_notif();
                clearInterval(setvar);
            setvar = setInterval('refresh_notif()',5000);
            }
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewUploader(){
    var xh = loadXMLDoc();
    var url = "uploader.php";

    xh.onreadystatechange = view_u;

    function view_u(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewGallery(){
     var xh = loadXMLDoc();
    var url = "gallery.php";

    xh.onreadystatechange = view_u;

    function view_u(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewPhoto(photo_id){
    
}

function viewFollowerProfile(){
     var xh = loadXMLDoc();
    var url = "profile_follow.php";

    xh.onreadystatechange = view_u;

    function view_u(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("profile_bottom").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewChangeProfile(){
    var xh = loadXMLDoc();
    var url = "changeprofile.php";

    xh.onreadystatechange = view_u;

    function view_u(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewEditFollower(){
     var xh = loadXMLDoc();
    var url = "profile.php?edit_follower=1";

    xh.onreadystatechange = view_u;

    function view_u(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewEditFollowing(){
     var xh = loadXMLDoc();
    var url = "profile.php?edit_following=1";

    xh.onreadystatechange = view_u;

    function view_u(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);

}

function viewOtherProfile(usr_tujuan){
    var xh = loadXMLDoc();
    var url = "otherprofile.php?UserTujuan="+usr_tujuan;

    xh.onreadystatechange = view_u;

    function view_u(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewMessageThread(msg_id, sub){
    var xh = loadXMLDoc();
    var url = "message_thread.php?msgid="+msg_id+"&sub="+sub;

    xh.onreadystatechange = view_u;

    function view_u(){
        if (xh.readyState==4 && xh.status==200){
        document.getElementById("content").innerHTML=xh.responseText;
    		}
    //		else {
    //			alert("Problem retrieving data:" + xh.statusText);
    //		}
    }
    //URLnya
    //onreadystatechange

    xh.open("GET",url,true);
    xh.send(null);
}

function viewPhoto(photo_id){

}

function viewEditDetailsPhoto(photo_id){

}

function removePhoto(photo_id){

}

function makeProfpic(photo_id){

}

function removePhotoComment(com_id, usr_id, body){

}

function deleteWallPost(wall_id){

}

var more = 0;

function viewMoreWallPost(wall_count, usr_tujuan){
    if (more == 0){
        var xh = loadXMLDoc();
        var url = "wall_posts.php?count="+wall_count+"&UserTujuan="+usr_tujuan;

        xh.onreadystatechange = view_w;

        function view_w(){
            if (xh.readyState==4 && xh.status==200){
            document.getElementById("more_posts").innerHTML=xh.responseText;
            document.getElementById("view_more").innerHTML = "<a href='javascript:viewLessWallPost("+ wall_count + ",\""+ usr_tujuan+"\")' id='headerLink'>view less posts...</a>";
       		}
        //		else {
        //			alert("Problem retrieving data:" + xh.statusText);
        //		}
        }
        //URLnya
        //onreadystatechange

        xh.open("GET",url,true);
        xh.send(null);
        more = 1;
    }
    else{
        viewLessWallPost(wall_count, usr_tujuan);
    }
}

function viewLessWallPost(wall_count, usr_tujuan){
    if (more == 1){

        document.getElementById("more_posts").innerHTML = "";
        document.getElementById("view_more").innerHTML = "<a href='javascript:viewLessWallPost("+ wall_count + ",\""+ usr_tujuan+"\")' id='headerLink'>view more posts...</a>";
        more = 0;
    }
    else{
        viewMoreWallPost(wall_count, usr_tujuan)
    }

}

//var more_com = 0;

function viewMoreWallComment(wall_id, wall_count, div_id, comm, body, usr_tujuan){
    //if (more_com == 0){
        var xh = loadXMLDoc();
        var url = "wall_comments.php?wallid="+wall_id+"&count="+wall_count+"&div_id="+div_id+"&comm="+comm+"&body="+body+"&UserTujuan="+usr_tujuan;

        xh.onreadystatechange = view_w;

        function view_w(){
            if (xh.readyState==4 && xh.status==200){
                document.getElementById("more_comments_"+div_id).innerHTML=xh.responseText;
                document.getElementById("view_more_com_"+div_id).innerHTML = "";
            }
        //		else {
        //			alert("Problem retrieving data:" + xh.statusText);
        //		}
        }
        //URLnya
        //onreadystatechange

        xh.open("GET",url,true);
        xh.send(null);
      //  more_com = 1;
   // }
//    else{
//        viewLessWallComment(wall_id, wall_count, div_id, comm, body);
//    }
}

//function viewLessWallComment(wall_id, wall_count, div_id, comm, body){
//    if (more_com == 1){
//
//        document.getElementById("more_comments_"+div_id).innerHTML = "";
//        document.getElementById("view_more_com_"+div_id).innerHTML = "<a href='javascript:viewMoreWallComment("+wall_id+","+ wall_count + "," +div_id+","+comm+","+body+")' id='headerLink'>view more comments...</a>";
//        more_com = 0;
//    }
//    else{
//        viewMoreWallComment(wall_id, wall_count, div_id, comm, body)
//    }
//
//}

function viewChat(){
     var xh = loadXMLDoc();
        var url = "chat.php";

        xh.onreadystatechange = view_w;

        function view_w(){
            if (xh.readyState==4 && xh.status==200){
                document.getElementById("content").innerHTML=xh.responseText;
            }
        }
        //URLnya

        xh.open("GET",url,true);
        xh.send(null);
}

function onloadPageChat() {
	document.getElementById("notif_number").innerHTML = refresh_notif();
	clearInterval(setvar);
	setvar = setInterval('refresh_notif()',5000);
	
}

var photo;


function viewPhotos(){
    var xh = loadXMLDoc();
        var url = "photogan.php";

        xh.onreadystatechange = view_w;

        function view_w(){
            if (xh.readyState==4 && xh.status==200){
                document.getElementById("photophoto").innerHTML=xh.responseText;
            }
        }
        //URLnya

        xh.open("GET",url,true);
        xh.send(null);
}

function reloadPhotos(){
    viewPhotos();
    clearInterval(photo);
    photo = setInterval('viewPhotos()',1000);
}